﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>修改密码</title>
    <meta name="viewport" content="width=device-width" />
    <link href="../../js/jquery-easyui-1.4/themes/default/easyui.css" rel="stylesheet"
        type="text/css" />
    <link href="../../js/jquery-easyui-1.4/themes/icon.css" rel="stylesheet" type="text/css" />
    <script src="../../js/jquery-easyui-1.4/jquery-1.8.0.min.js" type="text/javascript"></script>
    <script src="../../js/jquery-easyui-1.4/jquery.easyui.min.js" type="text/javascript"></script>
    <script src="../../js/jquery-easyui-1.4/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>
    <script src="../../js/jquery-easyui-1.4/easyui-validate.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {
            //获取并显示原始数据，如：用户名。
            $.getJSON("../../service/Password.ashx", { action: "GetSessionName", r: Math.random() }, function (data) {
                if (!data.error) {
                    $("#name,#loginname").val(data.msg);
                } else {
                    $.messager.alert("出错了", data.msg,'error');
                    top.window.location.replace("Login.html");
                }
            });
        });

        function reset() {
            $("#fm").form('reset');
        }

        function submitForm() {


            $('#fm').form('submit', {
                url: '../../service/Password.ashx?action=ModifyPassword',
                onSubmit: function (data) {
                    var newPwd = $("#newPwd").val();
                    var newPwd2 = $("#newPwd2").val();
                    var oldPwd = $("#oldPwd").val();
                    if (oldPwd.length == 0 || newPwd.length == 0 || newPwd2.length == 0) {
                        $.messager.alert('警告', '输入框不能为空', 'info');
                        return false;
                    }
                    if (newPwd != newPwd2) {
                        $("#newPwd").focus();
                        $.messager.alert('警告', '新密码两次输入不一致', 'info', function () {
                            $("#newPwd,#newPwd2").textbox("clear");
                            $('#newPwd').textbox().next('span').find('input').focus()
                        });
                        return false;
                    }

                    $.messager.progress();
                    return true;
                },
                success: function (result) {
                    result = eval('(' + result + ')'); //easyui form 不能将接受到的数据自动转换为javascript数组。
                    if (result.error) {
                        $.messager.alert("错误", result.msg, 'error');
                    }
                    else {
                        $.messager.alert('成功', '修改密码成功', 'info', function () {
                            top.window.location.replace("Login.html");
                        });
                       
                    }
                    $.messager.progress('close');
                }
            });
        }
    </script>
    <style type="text/css">
        body
        {
            margin: 1px !important;
            padding: 0;
        }

        .content
        {
            width: 400px;
            margin: 100px auto;
        }
    </style>
</head>
<body>
    <div class="content">
        <div id="p" class="easyui-panel" data-options="iconCls:'icon-user'" title="用户信息"
            style="width: 100%; height: 290px;">
            <div style="padding: 10px 60px 20px 60px">
                <form id="fm" method="post">
                    <table cellpadding="5">
                        <tr>
                            <td>用&nbsp;户&nbsp;名:
                            </td>
                            <td>
                                <input class="easyui-textbox" data-options="readonly:true" type="text" id="name" name="name" value="admin"></input>
                            </td>
                        </tr>
                        <tr>
                            <td>登&nbsp;录&nbsp;名:
                            </td>
                            <td>
                                <input class="easyui-textbox" data-options="readonly:true" type="text" id="loginname" name="loginname" value="admin"></input>
                            </td>
                        </tr>
                        <tr>
                            <td>原&nbsp;密&nbsp;码:
                            </td>
                            <td>
                                <input class="easyui-textbox" type="password" id="oldPwd" name="oldPwd" />
                            </td>
                        </tr>
                        <tr>
                            <td>新&nbsp;密&nbsp;码:
                            </td>
                            <td>
                                <input class="easyui-textbox" type="password" id="newPwd" name="newPwd" />
                            </td>
                        </tr>
                        <tr>
                            <td>确认新密码:
                            </td>
                            <td>
                                <input class="easyui-textbox" type="password" id="newPwd2" name="newPwd2" />
                            </td>
                        </tr>
                    </table>
                </form>
                <div style="text-align: center; padding: 5px">
                    <a href="javascript:void(0)" data-options="iconCls:'icon-ok'" class="easyui-linkbutton" id="btn_modify"
                        onclick="submitForm()">修 改</a> <a href="javascript:void(0)" data-options="iconCls:'icon-cancel'"
                            class="easyui-linkbutton" onclick="reset();">清 空</a>
                </div>
            </div>
        </div>
    </div>
</body>
</html>
